package org.smr.dev.javabean;

import java.util.HashMap;
import java.util.Map;

import org.smr.dev.AbstractCodeGenerator;
import org.smr.dev.CodeGenerator;
import org.smr.dev.EntityDefCreater;
import org.smr.dev.matedata.EntityDef;

public class JavaBeanCodeGenerator implements CodeGenerator {

	private String javaBeanTemplateFileName;

	private EntityDef javaBeanDefind;

	private String output2FilePathAndName;
	
	Map<String, Object> velocityVariables = new HashMap<String, Object>();


	public void generate(String tableName) {
		EntityDefCreater ec = new EntityDefCreater();
		EntityDef ed = ec.create(tableName);
		generate(ed);
	}

	private void generate(EntityDef ed) {

		Map<String, Object> velocityVariables = new HashMap<String, Object>();
		velocityVariables.put("package", "com.weimi.elec.entities.biz");
		velocityVariables.put("javaEntityBeanName", ed.getName());
		velocityVariables.put("fieldItems", ed.getFields());

		AbstractCodeGenerator ac = new AbstractCodeGenerator(javaBeanTemplateFileName, velocityVariables,
				output2FilePathAndName);
		ac.generate();
	}

	public void generate(Map<String, Object> codeVar){
		AbstractCodeGenerator ac = new AbstractCodeGenerator(javaBeanTemplateFileName, codeVar,
				output2FilePathAndName);
		ac.generate();
	}


	public JavaBeanCodeGenerator(String javaBeanTemplateFileName, String output2FilePathAndName) {
		super();
		this.javaBeanTemplateFileName = javaBeanTemplateFileName;
		this.output2FilePathAndName = output2FilePathAndName;
	}
	

}
